//
//  SearchSellerPaiPinViewController.m
//  com.yjwh.yj
//
//  Created by wei pan on 2019/4/19.
//  Copyright © 2019 ferver7. All rights reserved.
//

#import "SearchSellerPaiPinViewController.h"
//#import "YPAuctionDetailViewController.h"
//#import "AuctionDetailViewController.h"

@interface SearchSellerPaiPinViewController ()
@property (weak, nonatomic) IBOutlet UICollectionView *selfCollectionView;
@property (nonatomic,strong) NSMutableArray *dataArr;
@property (nonatomic,assign) NSInteger page;
@end

@implementation SearchSellerPaiPinViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    mNavitationTitle(@"拍品列表");
    self.automaticallyAdjustsScrollViewInsets = NO;//单独适配要优化
    self.page = 1;
    self.dataArr = [[NSMutableArray alloc]init];
    self.selfCollectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        self.page = 1;
        [self loadData];
    }];
    self.selfCollectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        self.page ++;
        [self loadData];
    }];
    [self loadData];
}
-(void)loadData
{
    NSMutableDictionary * parameters = [[NSMutableDictionary alloc]init];
    NSString * pageStr = [NSString stringWithFormat:@"%ld",self.page];
    setDickeyobj(parameters,pageStr, @"pgNo");
    setDickeyobj(parameters, @"12", @"num");
    setDickeyobj(parameters, self.sellerId, @"sellerUserId");
//    [PPNetworkHelper POST:auction_search_seller parameters:parameters success:^(id responseObject) {
//        [self.selfCollectionView.mj_header endRefreshing];
//        [self.selfCollectionView.mj_footer endRefreshing];
//        if (self.page == 1 && self.dataArr.count > 0) {
//            [self.dataArr removeAllObjects];
//        }
//        if (PPSUCCESS(responseObject)) {
//            for (NSDictionary * infoObj in responseObject[@"msg"]) {
//                [self.dataArr addObject:infoObj];
//            }
//        }else{
//            [AxcUI_Toast AxcUI_showCenterWithText:responseObject[@"desc"]];
//        }
//        [self.selfCollectionView reloadData];
//    } failure:^(NSError *error) {
//        [self.selfCollectionView.mj_header endRefreshing];
//        [self.selfCollectionView.mj_footer endRefreshing];
//    } showLoading:nil];
}
#pragma mark uicollectionViewDelegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArr.count == 0 ?1 :self.dataArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.dataArr.count == 0) {
        UICollectionViewCell * contentCell = mGetCollectionViewCell(@"noDataCell", indexPath);
        return contentCell;
    }
    UICollectionViewCell * contentCell = mGetCollectionViewCell(@"contentCell", indexPath);
    UIImageView * logoImage = mViewByTag(contentCell.contentView, 100, UIImageView);
    UILabel * priceLabel = mViewByTag(contentCell.contentView, 101, UILabel);
    UILabel * numsLabel = mViewByTag(contentCell.contentView, 102, UILabel);
    NSDictionary * infoDic = self.dataArr[indexPath.row];
    [logoImage sd_setImageWithURL:[NSURL URLWithString:infoDic[@"goodsImg"]] placeholderImage:mImageByName(@"home_Unloaded01_icon")];
    numsLabel.text = [NSString stringWithFormat:@"%@次出价",infoDic[@"bidCnt"]];
    priceLabel.text = [[NSString new] deleteFloatAllZero:[NSString stringWithFormat:@"%.2f",[infoDic[@"maxBidPrice"]floatValue]/100]];
    return contentCell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary * infoDic = self.dataArr[indexPath.row];
//    if ([infoDic[@"isYoupin"] integerValue] == 1) {
//        YPAuctionDetailViewController * aevc = mGetStoryboardViewController(@"YouPin", @"yPAuctionDetailViewController");
//        aevc.auctionId = infoDic[@"auctionId"];
//        [self.navigationController pushViewController:aevc animated:YES];
//    }else{
//        AuctionDetailViewController * advc = mGetStoryboardViewController(@"Main", @"auctionDetailViewController");
//        advc.auctionId = infoDic[@"auctionId"];
//        [self.navigationController pushViewController:advc animated:YES];
//    }
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.dataArr.count == 0) {
        CGFloat navHeight = getRectNavAndStatusHight;
        return CGSizeMake(mScreenWidth-24, mScreenHeight- navHeight-49);
    }
    return CGSizeMake((mScreenWidth-36)/2, (mScreenWidth-36)*213/330);
}
//这个是两行cell之间的间距（上下行cell的间距）
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 12;
}
//两个cell之间的间距（同一行的cell的间距）
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 12;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(12, 12, 12, 12);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
